﻿using QFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace ProjectSurvivor
{
    public class Dissolve : MonoBehaviour
    {

        public Material Material;

        private static readonly int mColor = Shader.PropertyToID("_Color");

        private static readonly int mFade = Shader.PropertyToID("_Fade");

        public Color DissolveColor;

        private void Start()
        {
            var material = Instantiate(Material);
            GetComponent<SpriteRenderer>().material = material;

            material.SetColor(mColor, DissolveColor);


            ActionKit.Lerp(1, 0, 0.5f, (fade) =>
            {
                material.SetFloat(mFade, fade);
                this.LocalScale(1 + (1 - fade) * 0.5f);
            }).
            Start(this, () =>
            {
                Destroy(material);
                this.DestroyGameObjGracefully();
            });
        }
    }
}
